package rwt.server.mtl;

import java.io.IOException;

import rwt.server.core.BaseMessage;

/**
 * A <i>message adaptor</i> converts RailMessages to and from Json format and byte array format. At present,
 * there are two implementations: the AdaMessageAdaptor and the JavaMessageAdaptor.
 */
public interface IMessageAdaptor
{
	/**
	 * Converts a message object to a byte array. The returned byte array follows the specification of the
	 * LocoNet or Controller software.
	 */
	public byte[] messageToBytes(BaseMessage message) throws Exception;
	
	/**
	 * Converts a byte array sent from the LocoNet or Controller to a message object.
	 */
	public BaseMessage bytesToMessage(byte[] bytes) throws Exception;
	
	/**
	 * Converts a JSON string to a message.
	 * 
	 * @param json JSON-formatted text
	 * @return A message object
	 */
	public BaseMessage jsonToMessage(String json) throws IOException;
	
	/**
	 * Converts a message to a JSON string.
	 * 
	 * @param message The message to convert
	 * @return A JSON string
	 */
	public String messageToJson(BaseMessage message) throws IOException;
}
